package eteam.aps.systemservice.dal;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import eteam.aps.systeminterface.model.entity.GroupuserEntity;
import eteam.aps.systemservice.dal.mapper.IGroupuserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户角色数据操作类
 */
@Service
public class GroupuserDal {
    @Autowired
    private IGroupuserMapper groupuserMapper;

    /**
     * 根据用户ID获取列表
     *
     * @param userid: 用户ID
     * @return: 列表数据
     */
    public List<GroupuserEntity> getListByUserId(String userid) {
        return groupuserMapper.selectList(new QueryWrapper<GroupuserEntity>().eq("FUserId", userid));
    }

    /**
     * 根据分组ID获取列表
     *
     * @param groupid: 分组ID
     * @return: 列表数据
     */
    public List<GroupuserEntity> getListByGroupId(String groupid) {
        return groupuserMapper.selectList(new QueryWrapper<GroupuserEntity>().eq("FGroupId", groupid));
    }

    /**
     * 根据用户ID删除关系
     *
     * @param userId
     * @return
     */
    public Integer deleteByUserId(String userId) {
        return groupuserMapper.delete(new QueryWrapper<GroupuserEntity>().eq("FUserId", userId));
    }

    /**
     * 保存角色用户
     *
     * @param groupuserList
     * @return
     */
    public void createGroupuser(List<GroupuserEntity> groupuserList) {
        for (GroupuserEntity item : groupuserList) {
            groupuserMapper.insert(item);
        }
    }
}